package DbUtil;

import java.sql.Connection;
import java.sql.DriverManager;
public class DatabaseConnection {
    //定义数据库驱动程序
    private static final String DBDRIVER="org.mariadb.jdbc.Driver";
    //数据库连接地址
    private static final String DBURL="jdbc:mariadb://122.114.69.20:3306/test";//example表示数据库
    private static final String DBUSER="mad_u0T_aon8xP";
    private static final String DBPASS="xoa`(PPz^#azox0-688hZx=8)";
    private Connection connection=null;
    public DatabaseConnection() throws Exception{
        try{
            //数据库操作可能出现异常
            Class.forName(DBDRIVER);
            connection=DriverManager.getConnection(DBURL,DBUSER,DBPASS);

        }catch(Exception exception ){
            throw exception;
        } finally {
        }
    }
    public Connection getConnection(){
        return connection;
    }
    public void close() throws Exception{
        if(connection!=null){
            try {
                connection.close();
            } catch (Exception e) {
                throw e;
            }
        }

    }

}

